package com.wlf.admin.system.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wlf.admin.common.dto.Const;
import com.wlf.admin.common.util.AjaxBean;
import com.wlf.admin.system.domain.ScheduleLog;
import com.wlf.admin.system.mapper.ScheduleLogMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class ScheduleLogService extends ServiceImpl<ScheduleLogMapper, ScheduleLog> {

    /**
     * 删除日志
     *
     * @param type 删除类型
     * @return 操作结果
     */
    public AjaxBean del(Const.DelType type, Long id) {
        switch (type) {
            case YEAR:
                this.lambdaUpdate().le(ScheduleLog::getCreateTime, LocalDateTime.now().minusYears(1)).eq(ScheduleLog::getJobId, id).remove();
                break;
            case YI:
                this.lambdaUpdate().le(ScheduleLog::getCreateTime, LocalDateTime.now().minusMonths(1)).eq(ScheduleLog::getJobId, id).remove();

                break;
            case SAN:
                this.lambdaUpdate().le(ScheduleLog::getCreateTime, LocalDateTime.now().minusMonths(3)).eq(ScheduleLog::getJobId, id).remove();

                break;
            case LIU:
                this.lambdaUpdate().le(ScheduleLog::getCreateTime, LocalDateTime.now().minusMonths(6)).eq(ScheduleLog::getJobId, id).remove();

                break;
            case ALL:
                this.lambdaUpdate().eq(ScheduleLog::getJobId, id).remove();
                break;
        }
        return AjaxBean.getOkMsg();
    }
}
